<template>
    <div>
        <!-- 头部 -->
        <div>
        <!-- 查询 -->
        <el-popover placement="bottom-start" width="1000" style="box-shadow: 0 0 8px rgba(0,0,0,.5);" trigger="click">
            <el-form :inline="true" :model="search">
                    <el-form-item label="部件名称" >
                        <el-input v-model="search.name" style="width: 100px;"></el-input>
                    </el-form-item>
                    <el-form-item label="部件编码">
                        <el-input v-model="search.code" style="width: 100px;"></el-input>
                    </el-form-item>
                    <el-form-item label="是否启用">
                        <el-select v-model="search.isEnable" placeholder="请选择">
                             <el-option label="【空】" value=""></el-option>
                            <el-option label="启用" value="1"></el-option>
                            <el-option label="未启用" value="0"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-form-item label="机器型号">
                        <el-select v-model="search.type" placeholder="请选择">
                            <el-option label="【空】" value="" ></el-option>
                            <el-option :label="item.type" :value="item.id" v-for="item in allType" :key="item.id"></el-option>
                        </el-select>
                    </el-form-item>
                    <el-button type="primary" @click="searchData" icon="el-icon-search">查询</el-button>
                </el-form>
            <el-button slot="reference" type="primary">查询</el-button>
        </el-popover>
        </div>
        <el-table :data="tableData" :highlight-current-row="true" stripe border class="table-index" :height="tableHeight" style="width: 100%;" :header-cell-style="getRowClass">
               <el-table-column fixed type="index" label="*" sortable min-width="40"></el-table-column>
             <el-table-column prop="typeName" label="机器型号" sortable  min-width="130"></el-table-column>
             <el-table-column prop="name" label="部装工序名称" sortable min-width="160"></el-table-column>
              <el-table-column prop="code" label="部装部件编码" sortable min-width="120"></el-table-column>
             <el-table-column prop="rank" label="工序生产顺序" sortable  min-width="130"></el-table-column>
             <el-table-column prop="useTime" label="工序生产时间定额(分钟)" sortable  min-width="130"></el-table-column>
            <el-table-column prop="nums" label="部件数量/台" sortable  min-width="130"></el-table-column>
            <el-table-column prop="isEnable" label="是否启用" sortable :formatter='formartIsEnable' min-width="120"></el-table-column>
            <el-table-column prop="creatorName" label="创建人" sortable min-width="100"></el-table-column>
            <el-table-column prop="createTime" label="创建时间" sortable min-width="160"></el-table-column>
            <el-table-column fixed="right" label="操作" sortable align="center" width="160">
                <template slot-scope="scope">
                    <el-button @click="showDialog(scope.row)" type="text" size="small">配置</el-button>
                </template>
            </el-table-column>
        </el-table>
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange" :current-page="pagination.currentPage" :page-sizes="[5,10, 15,20, 25,30,50, 100]" :page-size="pagination.pageSize" layout="total, sizes, prev, pager, next, jumper" :total="pagination.total"></el-pagination>
        <el-dialog :title="dialog.title" width="90%"  center :visible.sync="dialog.isShow" :close-on-click-modal="false" v-dialogDrag>
            <check-table :list="dialog.tableList" @addUpdateCheck='addUpdateCheck'></check-table>
        </el-dialog>
         <el-dialog :title="dialog1.title"   center :visible.sync="dialog1.isShow" :close-on-click-modal="false" v-dialogDrag>
            <check-config :dialogForm="dialog1.formData"  @addUpdate="addUpdateHandle"></check-config>
        </el-dialog>
    </div>
</template>
<script>
import api from '@/axios/api.js';
import scybHttp from '@/axios/scybHttp.js';
import cgbHttp from '@/axios/cgbHttp.js';
import qualitySystem from '@/axios/qualitySystem.js';
import machineHttp from '@/axios/machine.js';
import checkConfig from '@/components/page/companyManage/scyb/baseConfig/components/checkConfig.vue'
import checkTable from '@/components/page/companyManage/scyb/baseConfig/components/checkTable.vue'
import postSaleApi from '@/axios/postSale.js'
export default {
    components:{
        checkConfig,
        checkTable
    },
    data(){
        return {
             tableHeight: document.documentElement.clientHeight - 170,/**表格高度 */
             tableDialogHeightTabPane:{/**dialog style */
                height: (document.documentElement.clientHeight - 300) + 'px',
                overflowY: 'auto'
            },
            allType:[],
            search:{
                name:'',
                code:'',
                isEnable:'',
                type:''
            },
            tableData:[],
            loading:false,/**加载参数 */
            dialog:{
                title:'',
                isShow:false,
                pid:'',
                tableList:[]
            },
             pagination:{/**分页 */
                pageSize:10,
                currentPage:1,
                total:0
            },
            dialog1:{
                title:'',
                isShow:false,
                formData:{}
            }

        }
    },
    created(){
        let self = this;
        self.getTableList();
         /**获取所有机型 */
        scybHttp.bzAllJy().then(res=>{
            res.content.forEach(el=>{
                el.value=el.type
            })
            self.allType=res.content
        })
    },
    methods:{
        getAllDraw(){
            let self = this;
            machineHttp.bZDrawingKeywords(data).then(res=>{
                self.allDrawing=res.content;
            })
        },
        getTableList(){
            let self =this;
            let postData={
                currentPage:self.pagination.currentPage,
                pageSize:self.pagination.pageSize,
                name:self.search.name,
                code:self.search.code,
                isEnable:self.search.isEnable,
                type:self.search.type
            }
            api.partsConfigList(postData).then(res=>{
               self.tableData=res.content.records;
               self.pagination.total=res.content.total;
            })
        },
        formartIsEnable(row, column, cellValue, index){
            return cellValue == 1 ? '启用' : (cellValue == 0 ? '未启用' : "");
        },
        searchData(){
            this.pagination.currentPage=1;
            this.getTableList();
        },
        handleCurrentChange(current){
            this.pagination.currentPage=current;
            this.getTableList();
        },
        handleSizeChange(size){
            this.pagination.currentPage=1;
            this.pagination.pageSize=size;
            this.getTableList();
        },
        showDialog(row){
            let self = this;
            self.dialog.title = '维修过程配置';
            self.dialog.isShow = true;
            self.dialog.pid = row.id;
            self.getRepairConfigList();
        },
        getRepairConfigList(){
            let self = this;
            postSaleApi.repairConfigList(self.dialog.pid).then(res=>{
                self.dialog.tableList = res.content;
            })
        },
        addUpdateCheck(data){
            let self = this;
            let row =data.row;
            let type = data.type;
            self.dialog1.title = type==='insert'?'新增维修过程配置':'修改维修过程配置';
            self.dialog1.isShow = true;
            self.dialog1.formData = (type==='insert'?{
                        pid:self.dialog.pid,
                        name:'',//名字
                        reference:'',//参考值
                        unit:'',//单位
                        type:'',//类型
                        rank:'',
                        isEnable:'1',//是否使用
                        creatorName:'',
                        createTime:''
                    }:{
                        id:row.id,
                        pid:row.pid,
                        name:row.name,//名字
                        reference:row.reference,//参考值
                        unit:row.unit,//单位
                        type:row.type,//类型
                        rank:row.rank,
                        isEnable:String(row.isEnable),//是否使用
                       creatorName:row.creatorName,
                        createTime:row.createTime
                    });
        },
        addUpdateHandle(data){
           let self = this,
            type=self.dialog1.title.indexOf('新增')>-1?'insert':'update';
            postSaleApi.addUpdateRepairConfig(type,data).then(res=>{
                self.getRepairConfigList();
                self.dialog1.isShow=false;
                self.$message.success(`${self.dialog1.title}成功`)
            })
        }
    }
}
</script>
<style scoped>
.searchBox{
    width:200px;
    margin-top:24px;
}
.dec{
    color:#999;
    font-size: 12px;
    line-height: 1;
}
.width300{
    width:300px;
}
.name{
    line-height: 1.6;
    padding-top:5px;
}
.addr{
    font-size: 12px;
    color:#b4b4b4;
    line-height: 1;
    padding-bottom:5px;
}
</style>
